﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zor_DAL;
using Zor_Modes;
using Zor_Tools;


namespace Zor_Bll
{
        /// <summary>
        /// 销号管理
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public class Zor_Disannul_Bll<T> where T : class
        {
            /// <summary>
        /// 获取销号管理列表
        /// </summary>
        /// <param name="Model"></param>
        /// <param name="index"></param>
        /// <param name="TotalCount"></param>
        /// <param name="where"></param>
        /// <returns></returns>
        public static List<T> GetDisannulPageList(dynamic Model, int index, out int TotalCount, string where)
        {

            return PagerHelp<T>.GetPagerList(index, "V_Zor_Disannul", "Dn_Id", out TotalCount, GetSearchWhere(Model, where));
        }

        /// <summary>
        /// 获取消号管理列表
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="TotalCount">返回值</param>
        /// <returns></returns>
        //public static List<T> GetPageListDisannul(dynamic Model, int index, out int TotalCount, string where)
        //{
        //    return PagerHelp<T>.GetPagerList(index, "V_Zor_Summary", "Sm_Id", out TotalCount, GetSearchWhere(Model, "User_Id=" + RequestSession.GetSessionUser().User_Id + "  and Sm_State!=0"));
        //}
        

        /// <summary>
        /// 获取未销号管理列表
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="TotalCount">返回值</param>
        /// <returns></returns>
        public static List<T> MGetPageList(int index, out int TotalCount, string where)
        {
            return PagerHelp<T>.GetPagerList(index, "V_Zor_Summary", "Sm_Id", out TotalCount, where);
        }

        /// <summary>
        /// 消号
        /// </summary>
        /// <param name="accpid">受理单ｉｄ</param>      
        /// <param name="actualtax">税金总和</param>
        /// <param name="dndate">消号时间</param>     
        /// <param name="Jksbh">缴款书编号</param>   
        /// <param name="Sm_Id">汇总主键ｉｄ </param>
        /// 受理状态(0保存,1提交2被退回、3已评议4已评定5、已审核、6已缴税、7、已开票8、已消号、9已汇总)
        /// <returns></returns>
        public static BaseAnswer SummaryDisannul(int Dn_Id, string[] accpid, double Grsds, double Fcs, double actualtax, int dndate, string Jksbh, string[] Bd_Id)
        {
            BaseAnswer bar = Zor_Disannul_DAL<T>.SummaryDisannul(Dn_Id, accpid, Grsds, Fcs, actualtax, dndate, Jksbh, Bd_Id);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "消号成功！" : "消号失败！";
            return bar;
        }
        #region 私有函数
        /// <summary>
        /// 查询条件
        /// </summary>
        /// <param name="Model"></param>
        /// <param name="where"></param>
        /// <returns></returns>
        private static string GetSearchWhere(dynamic Model, string where)
        {

            var sqlSurch = string.Empty;
            if (Model.DnUser != null)
            {
                sqlSurch += " and DnUser like '%" + Model.DnUser + "%'";
            }
            if (Model.Dn_Date != null)
            {
                sqlSurch += " and Dn_Date >=" + TimeHelper.ToTimeStamp(DateTime.Parse(Model.Dn_Date.ToString())) + " and Dn_Date<=" + TimeHelper.ToTimeStamp(DateTime.Parse(Model.Dn_Date.ToString())) + "";
            }

            if (Model.DnState != null)
            {
                if (Model.DnState == "全部")
                {
                    sqlSurch += " and DnState  in ('待消号','已消号')";
                }
                else
                {
                    sqlSurch += " and DnState = '" + Model.DnState + "'";
                }
            }

            return where + sqlSurch;
        }
        #endregion

    }

   
}
